Fixed Stream find hang.#10310
Conversation
Fixed hang: while (!Serial1.find(0xCA)) ;
👋 Hello NathanSweet, we appreciate your contribution to this project! Click to see more instructions ...
Review and merge process you can expect ...
|
|
Hi @NathanSweet ! Thank you for the PR. Please note that Stream and other Arduino classes come from upstream. I suggest you propose your fix first in the official Arduino core API and when accepted, let us know so we can update it on our end. I will close this PR for now |
|
@me-no-dev I looked at Stream.cpp over there and they have fixed the problem: Why is the Arduino code in your repo so out of date? |
There are quite a few reasons why that is so. I'll update the class. Can you please post an issue, so we can track it's progress? |
|
Here is the update #10328 |
|
Cool, thank you! I didn't mean to be rude, it's just surprising to see a dependency forked and missing fixes from 6 years ago. I guess the Arduino codebase has done things that aren't agreeable with ESP32? |
Description of Change
Check
timedReadis < 0, then usechar(rather thanint) for the rest offindMulti. This avoids sign extension and incorrect comparisons which result in a hang.Tests scenarios
This code hangs forever, even when Serial repeatedly receives 0xCA, tested on Arduino Mega 2560 R3:
The reason is in Stream
findMulti:https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/Stream.cpp#L132
Consider this comparison:
cisintwith an unsigned value 0xCA.t->strisconst char *with (on Arduino Mega 2560 R3) a signed value -54 decimal which as an unsigned value is 0xCA.In the comparison, the char is sign extended to an int, resulting in 0xFFFFFFCA giving:
This is never true and not the intention. There appear to be other comparisons in Stream.cpp with this problem.